#region Using directives
using System;
using System.Text ;
using System.Data ;
using System.Collections ;
using WP.RM.DataEntity; 
using WP.RM.DataAccess; 
using WP.RM.BusinessRule ; 
using WP.DB;
using WP.Commons;
#endregion
namespace WP.RM.BusinessLogical
{

    /*
     * Created by SmartCreateCode Tool
     * At 4/22/2005
     */

    public class RMCategoryBLL : IBusinessLogical
    {

        RMCategoryDAL rmCategoryDAL = new RMCategoryDAL();

        public RMCategoryBLL()
        {
        }

        #region For implement interface

        #region Select Record by RECID OverLoad +1
        public RMCategoryDEL  SelectDataByRecID(DBAccess dBAccess, string strRecId)
        {
            RMCategoryDEL rmCategoryDEL = new RMCategoryDEL();

            DataFunctions.SelectByRecID(dBAccess, rmCategoryDEL, rmCategoryDAL.Fields, strRecId);

            return rmCategoryDEL;
        }
        public IDataEntity SelectDataByRecID(string strRecId)
        {
            DBAccess dBAccess = new DBAccess(false, false);
            RMCategoryDEL rmCategoryDEL = null;

            try
            {
                rmCategoryDEL = SelectDataByRecID(dBAccess, strRecId);
                return rmCategoryDEL as IDataEntity;
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
                return null;
            }
            finally
            {
                dBAccess.CloseCon();
            }
        }
        #endregion

        #region public bool Insert()
        public bool Insert(IDataEntity iRMCategoryDEL)
        {
            bool bReturn = true;
            RMCategoryDEL rmCategoryDEL = iRMCategoryDEL as RMCategoryDEL;
            DBAccess dBAccess = null;

            dBAccess = new DBAccess(false, true);
            try
            {
                bReturn = Insert(dBAccess, rmCategoryDEL);

                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                bReturn = false;
            }
            return bReturn;
        }
        public bool Insert(DBAccess dBAccess, RMCategoryDEL rmCategoryDEL)
        {
            bool bFlag = true;
            RMCategoryBRL rmCategoryBRL = new RMCategoryBRL();

            if (rmCategoryBRL.InsertValid(dBAccess, rmCategoryDEL))
            {
                DataFunctions.InsertTable(dBAccess, rmCategoryDAL.Fields, rmCategoryDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
        #endregion

        #region public bool Delete()
        public bool Delete(string strRecId, byte[] btOldRecStamp)
        {
            DBAccess dBAccess = new DBAccess(false, true);
            bool bFlag = false;

            try
            {
                if (new RMCategoryBRL().DeleteValid(dBAccess, strRecId, btOldRecStamp))
                {
                    DataFunctions.DeleteByRecID(dBAccess, "rmCategory", strRecId);

                    dBAccess.CommitTranAndCloseCon();

                    bFlag = true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
            }

            return bFlag;
        }
        #endregion

        #region public bool Update()
        public bool Update(IDataEntity iRMCategoryDEL)
        {
            bool bReturn = true;
            RMCategoryDEL rmCategoryDEL = iRMCategoryDEL as RMCategoryDEL;
            DBAccess dBAccess = new DBAccess(false, true);

            try
            {
                bReturn = Update(dBAccess, rmCategoryDEL);
                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }

            return bReturn;
        }
        public bool Update(DBAccess dBAccess, RMCategoryDEL  rmCategoryDEL)
        {
            bool bFlag = true;
            RMCategoryBRL rmCategoryBRL = new RMCategoryBRL();

            if (rmCategoryBRL.UpdateValid(dBAccess, rmCategoryDEL))
            {
                DataFunctions.UpdateTable(dBAccess, rmCategoryDAL.Fields, RMCategoryDEL.TABLENAME_RMCategroy, rmCategoryDEL.Tables[0].Rows[0]);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
        #endregion

        #endregion

    }
}